package com.walker.component.page.resolve.query;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.walker.component.utils.DateUtils;

/**
 * 字符串查询器
 * 
 * @author 三丰
 * 
 */
public class DateQueryer extends GeneralQueryer<Long> {
	private boolean showDefaultTime = false;//默认值
	private String dateFormat = "";//日期格式

	public void setShowDefaultTime(boolean showDefaultTime) {
		this.showDefaultTime = showDefaultTime;
	}
	public void setDateFormat(String dateFormat) {
		this.dateFormat = dateFormat;
	}

	public DateQueryer() {
	}

	public DateQueryer(String cssExpression) throws IllegalArgumentException {
		setCssQuery(cssExpression);
	}

	@Override
	public Long convert(Object obj) {
		String dateString = (String) obj;
		long milliseconds=0;
		if ((StringUtils.isEmpty(dateString)) && showDefaultTime) {
			return new Date().getTime();
		}
		if(StringUtils.isEmpty(dateString)){
			return 0l;
		}
		milliseconds=DateUtils.str2DateMilliseconds(dateString,dateFormat);
		return milliseconds;
	}
}
